<?php
/**
 * Note: 菜单
 * Date: 2020/03/23
 */
namespace App\Models;

use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Menu extends Base
{
    public const STATUS_OFF = 0;
    public const STATUS_ON = 1;

    use ModelTrait;

    protected $table = 'menus';

    protected $fillable = [
        'pid',
        'access_id',
        'name',
        'route',
        'url',
        'icon',
        'sort',
        'status',
    ];

    protected $hidden = [];

    protected $appends = [];

    /**
     * 关联权限
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function roleAccess()
    {
        return $this->belongsTo('App\Models\RoleAccess', 'access_id', 'id')->withDefault();
    }

    /**
     * 父级菜单
     * @return HasOne
     */
    public function parentMenu()
    {
        return $this->hasOne(Menu::class, 'id', 'pid');
    }
}
